package controller;

import com.github.pagehelper.PageInfo;
import entity.LayRequest;
import entity.MyResult;
import entity.Permission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.PermService;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/perm")
public class PermissionController {
    @Autowired
    private PermService permService;

    @ResponseBody
    @RequestMapping("/laylist")
    private MyResult<List<Permission>> list(LayRequest layRequest, HttpSession httpSession){
        PageInfo<Permission> permissionPageInfo = permService.selectByPage(layRequest);
        return new MyResult<>(0,permissionPageInfo.getTotal(),permissionPageInfo.getList());
    }

    @RequestMapping("/toAdd")
    private String toAdd(){
        return "add.jsp";
    }

    @ResponseBody
    @RequestMapping("/add")
    private MyResult insert(Permission permission){
       boolean insert=permService.insert(permission);
       return new MyResult<>(0);
    }
}
